// debugging
var drag_status;
$(document).ready(function() {
  drag_status = $("#drag_status")[0];
});

var dnd = {
  scb : function() { // start drag callback
    alert("no start drag callback function set");
  },

  dcb : function() { // drop callback
    alert("no drop callback function set");
  },

  start : function(e) {
    this.start_time = new Date().getTime();
    this.source = e.target;
    this.value = $(e.target).attr("data-value");
    if (drag_status) { // debugging
      drag_status.innerHTML = "start { time = " + this.start_time +
        ", value = " + this.value + " }<br/>" + drag_status.innerHTML;
    }
    if (e.target instanceof HTMLCanvasElement) {
      e.dataTransfer.setData("Text", this.value); // doesn't work without this line but can't get data at drop...wierd
    } else {
//      e.preventDefault(this.source, this.value);
    }
    this.scb();
  },

  setStartCallBack : function(cb) {
    this.scb = cb;
  },

  drag : function(e) {
    var x = 0;
  },

  dragEnd : function(e) {
    this.end_time = new Date().getTime();
  },

  over : function(e) {
    e.preventDefault();
  },

  drop : function(e) {
    this.drop_time = new Date().getTime();
    this.target = e.target;
    if (drag_status) { // debugging
      drag_status.innerHTML = "drop { time = " + this.drop_time +
        ", value = " + this.value + " }<br/>" + drag_status.innerHTML;
    }
    if (this.value != "-1") {
      this.dcb(this.target, this.value);
    }
    e.preventDefault();
  },

  setDropCallBack : function(f) {
    this.dcb = f;
  }
};
